export class ApiResponse<T = any> {
  code: number;
  message: string;
  data?: T;

  constructor(code: number, message: string, data?: T) {
    this.code = code;
    this.message = message;
    this.data = data;
  }

  public static success<T = any>(
    data: T,
    message = '操作成功',
  ): ApiResponse<T> {
    return new ApiResponse(0, message, data);
  }

  public static fail(message = '操作失败', code = 1): ApiResponse<null> {
    return new ApiResponse(code, message, null);
  }
}
